ComponentOne Data Source for Entity Framework
C1.LiveLinq.Indexing Namespace / IndexingAlgorithm Class / CreateIndex<T,TKey>(IObservableSource<T>,Expression<Func<T,TKey>>,Boolean,CultureInfo) Method
The type of the elements of the collection to index.
The type of the index key.
The collection to be indexed.
Key selector expression of the index, see KeySelector.
Specifies whether the key used in this index is a unique key for the indexed collection.
Locale information used to compare strings in the index (default: CultureInfo.CurrentCulture).

In This Topic
    CreateIndex<T,TKey>(IObservableSource<T>,Expression<Func<T,TKey>>,Boolean,CultureInfo) Method
    In This Topic
    Creates a new index.
    Syntax
    'Declaration
     
    
    Public Function CreateIndex
        (Of T,TKey)( _
       ByVal source As IObservableSource(Of T), _
       ByVal keySelector As System.Linq.Expressions.Expression(Of Func(Of T,TKey)), _
       ByVal keyIsUnique As System.Boolean, _
       ByVal locale As System.Globalization.CultureInfo _
    ) As Index(Of T,TKey)
    public Index<T,TKey> CreateIndex<T,TKey>( 
       IObservableSource<T> source,
       System.Linq.Expressions.Expression<Func<T,TKey>> keySelector,
       System.bool keyIsUnique,
       System.Globalization.CultureInfo locale
    )

    Parameters

    source
    The collection to be indexed.
    keySelector
    Key selector expression of the index, see KeySelector.
    keyIsUnique
    Specifies whether the key used in this index is a unique key for the indexed collection.
    locale
    Locale information used to compare strings in the index (default: CultureInfo.CurrentCulture).

    Type Parameters

    T
    The type of the elements of the collection to index.
    TKey
    The type of the index key.

    Return Value

    The new index.
    Remarks

    Normally, you don't need to use this method. Indexes are usually created in code by calling IndexCollection.Add, or their creation can be enforced in LINQ queries by using the Indexed hint. This method should be used only in special situations where all you want is to index a collection without an overhead of maintaining a collection of indexes, or you need an index that exists separately from the collection of indexes maintained by the source. Unlike the standard ways of creating indexes, this method only creates an index object and attaches it to the source (so it will be automatically synchronized with the source when the source is modified), but the created index is not added to IndexCollection<T>.

    A unique index occupies less memory and performs better than a non-unique index (although the difference isn't dramatic). Therefore, for unique keys, it's recommended to specify the corresponding index as unique. But do that only if you are sure that the key is indeed unique, as it imposes a uniqueness constraint on the indexed collection. An attempt to modify the indexed collection violating the uniqueness throws an System.InvalidOperationException.

    See Also